runescapefandomcom_pt-20200214-history
Módulo:Sugestões de aparato
local p = {} local matnames = mw.loadData('Module:Desmontar/mats') local perknames = mw.loadData('Module:Aparatos/data') local perkmats = mw.loadData('Module:Aparatos/materiais') local yn = require('Module:Yesno') function plink(mat) if mat then local matplain = string.lower(mat) :gsub('components?', ) :gsub('parts?', '') mat = matplain mw.text.trim(mat) mat = matnamesmat if mat then local class = '' if mat:find('parts') then class = 'gizmo-interface-parts' end return string.format(' ', mat, mat), class, matplain end end return '' end function perklink(perk) local working = mw.text.split(perk, '%local a = working[1 local b = working2 or '' local c if b '' then working = mw.text.split(a, '%(') a = working1 c = working2 or '' else working = mw.text.split(b, '%(') b = working1 or '' c = working2 or '' end b = b:gsub('%]',) :gsub('-', '–') c = c:gsub('%)', ) local name, rankmin, rankmax local rankstr = '' local comment = '' if a then a = mw.text.trim(a:lower()) name = perknamesa.name rankstr = ' ' .. mw.text.trim(b) if c ~= '' then comment = string.format(' (%s)', mw.text.trim©) end else return nil end local span = mw.html.create('span') span:css({ background = '#09222F', 'border-radius' = '111px', width = '35px', height = '35px', 'line-height' = '30px', 'text-align' = 'center', display = 'inline-table', }) :wikitext(string.format(' ', name, name)) return string.format('\n* %s %s%s%s', tostring(span), name, name:gsub('%(perk%)', ''), rankstr, comment), a end function otherperks(mats, perks, gizmos) local allperks = {} local fperks = {} local ret = {} for m,n in pairs(mats) do if perkmatsm then for p,t in pairs(perkmatsm.perks) do if tn1 > 0 and tn2 > 0 then allperksp = true end end end end --detect gizmos local appgizmos = { weapon = true, armour = true, tool = true } local p2 for p,_ in pairs(perks) do p2 = perknamesp for i,v in pairs(appgizmos) do appgizmosi = v and p2i end end -- overrides for i,v in pairs(gizmos) do appgizmosi = v end -- test for issues if not appgizmos.weapon and not appgizmos.armour and not appgizmos.tool then --table.insert(ret, "\n:* '''Error: perks selected can't be in the same gizmo. Defaulting to showing all'") appgizmos = { weapon = true, armour = true, tool = true, } end --filter allperks for p,_ in pairs(allperks) do p2 = perknamesp for i,v in pairs(appgizmos) do if v and p2i then fperksp = p2.name break end end end -- make string for p,n in pairs(fperks) do if not perksp then table.insert(ret, string.format('\n:* %s',n,n:gsub(' %(perk%)',''))) end end return ret end function p.main(frame) local args = frame:getParent().args local ret = {} local matnums = {} local mati for i=1,5,1 do mati = 'mat' .. i retmati = { plink(argsmati or argsi) } if retmati1 ~= '' then matnums[retmati3] = (matnums[retmati3] or 0) + 1 end end local perks = mw.text.split(args.perks, '%s*,%s*') local perkl = {} local perkplain = {} local pl, pplain for i,v in ipairs(perks) do pl, pplain = perklink(v) if pl then table.insert(perkl, pl) perkplainpplain = true end end ret.perks = table.concat(perkl, '') local gizmos = { weapon = yn(args.weapon), armour = yn(args.armour), tool = yn(args.tool), } if not yn(args.otherperks or 'yes') then ret.other = '' else ret.other = table.concat(otherperks(matnums, perkplain, gizmos), '') end return p._main(ret) end function p._main(args) local ret = mw.html.create('tr') ret:tag('td') :tag('table') :addClass('gizmo-interface') :tag('tr') :tag('td') :done() :tag('td') :addClass(args.mat12) :wikitext(args.mat11) :done() :tag('td') :done() :done() :tag('tr') :tag('td') :addClass(args.mat22) :wikitext(args.mat21) :done() :tag('td') :addClass(args.mat32) :wikitext(args.mat31) :done() :tag('td') :addClass(args.mat42) :wikitext(args.mat41) :done() :done() :tag('tr') :tag('td') :done() :tag('td') :addClass(args.mat52) :wikitext(args.mat51) :done() :tag('td') :done() :done() :done() :done() if args.other ~= '' then ret:tag('td') :wikitext(args.perks) :wikitext('\n') :tag('div') :addClass('mw-collapsible mw-collapsed') :attr({ 'data-expandtext' = 'show', 'data-collapsetext' = 'hide', }) :wikitext('\n* Other possible perks:\n') :tag('div') :addClass('mw-collapsible-content') :wikitext(args.other) :done() :done() :done() else ret:tag('td') :wikitext(args.perks) :done() end return ret end return p